package club.emergency.wechat.manager.operate.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.manager.operate.consumer.service.ManagerOperateConsumer;
import club.emergency.wechat.model.manager.Manager;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.manager.operate.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class ManagerOperateFallbackFactory implements FallbackFactory<ManagerOperateConsumer> {
    @Override
    public ManagerOperateConsumer create(Throwable throwable) {
        return new ManagerOperateConsumer() {
            @Override
            public String save(Manager manager) {
                return ResponseEntity.error(StatusCode.DB_SAVE_ERROR, "新增人员失败！", throwable.getMessage());
            }

            @Override
            public String modify(Manager manager) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "修改人员失败！", throwable.getMessage());
            }

            @Override
            public String removeById(Long id) {
                return ResponseEntity.error(StatusCode.DB_REMOVE_ERROR, "删除人员失败！", throwable.getMessage());
            }
        };
    }
}
